package com.shenhua.kunpeng.utils;
import com.shenhua.kunpeng.config.HikariCofig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;

public class DataSourceUtil {
    public static DataSource createDataSource(HikariCofig cofig) {
        HikariDataSource hikariDataSource = new HikariDataSource();
        hikariDataSource.setDriverClassName(cofig.getDriverClassName());
        hikariDataSource.setJdbcUrl(cofig.getUrl());
        hikariDataSource.setUsername(cofig.getUsername());
        hikariDataSource.setPassword(cofig.getPassword());
        hikariDataSource.setMinimumIdle(cofig.getMinimumIdle());
        hikariDataSource.setIdleTimeout(cofig.getIdleTimeout());
        hikariDataSource.setMaximumPoolSize(cofig.getMaximumPoolSize());
        hikariDataSource.setMaxLifetime(cofig.getMaxLifetime());
        hikariDataSource.setConnectionTimeout(cofig.getConnectionTimeout());
        hikariDataSource.setConnectionTestQuery(cofig.getConnectionTestQuery());
        return hikariDataSource;
    }
}
